//
//  BDMBaseOperationManagerLib3.h
//  welkin
//
//  Created by liyingpeng on 16/4/29.
//  Copyright © 2016年 com.baidu.cid. All rights reserved.
//

#import "AFHTTPSessionManager.h"
#import "BDMHTTPRequestModel.h"
#import "BDMError.h"
#import "BDMUploadFileModel.h"
#import "BDMDownloadFileModel.h"

typedef void(^ConfigHeaderBlock)(NSMutableURLRequest * _Nonnull request, NSDictionary * _Nonnull aParameters, NSDictionary * _Nonnull aCustomerHeader);
typedef NSError * _Nonnull(^ConfigResultHandlerBlock)(id _Nonnull responseObject, BOOL isResponseJSONValid, NSInteger statusCode);
typedef NSCachedURLResponse * _Nonnull (^ConfigAdoptCachePolicyBlock)(NSMutableURLRequest * _Nonnull aRequest, NSCachedURLResponse * _Nonnull response, BOOL isResponseJSONValid);
typedef BDMHTTPRequestModel * _Nonnull (^ConfigRequestModelHandlerBlock)(BDMHTTPRequestModel * _Nonnull requestModel);

@interface BDMBaseOperationManager : NSObject

@property(nonatomic, copy, nullable)ConfigHeaderBlock configHeaderBlock;
@property(nonatomic, copy, nullable)ConfigResultHandlerBlock configResultHandlerBlock;
@property(nonatomic, copy, nullable)ConfigAdoptCachePolicyBlock configAdoptCachePolicyBlock;
@property(nonatomic, copy, nullable) ConfigRequestModelHandlerBlock configRequestModelBlock;

+ (_Nonnull instancetype)manager;

/*!
 @method
 @abstract 初始化缓存大小
 @discussion
 @result
 */
- (void)urlCacheInitialization;

/*!
 @method
 @abstract 清除所有url缓存
 @discussion
 @result
 */
- (void)clearAllURLCache;

/*!
 @method
 @abstract 发送Http请求
 @discussion
 @param aRequestModel 请求数据model
 @param aSuccessBlock 成功block
 @param　aFailureBlock　失败block
 @result
 */
-(void)sendHttpRequestWithModel:(nullable BDMHTTPRequestModel *) aRequestModel
                        success:(nullable void (^)(id _Nullable responseObject))aSuccessBlock
                        failure:(nullable void (^)(BDMError * _Nullable error))aFailureBlock;

/*!
 @method
 @abstract 批量发送Http请求
 @discussion
 @param modelArray 请求数据model数组
 @param progress 每个请求执行的回调
 @param complete 所有请求执行完后的回调
 @param　isResultRestrict　结果是否严格限制（yes表示每有一个请求失败立刻执行complete，
 no 表示单个的请求失败并不影响整体的回调，依然会等最后一个回调执行后再执行complete）
 @result
 */
- (void)sendHttpRequestGroupWithModelArray:(nullable NSArray<BDMHTTPRequestModel *> *)modelArray
                                  progress:(nullable void(^)(id _Nullable responseObject, NSString * _Nullable identifier, BDMError * _Nullable error))progress
                                  complete:(nullable void(^)(BOOL isRequestSuccess))complete
                          isResultRestrict:(BOOL)isResultRestrict;

/**
 *  @brief  上传文件时调用方法
 *
 *  @param aUploadFileModel 上传数据的model
 *  @param aProgressBlock   上传进度block
 *  @param aSuccessBlock    成功block
 *  @param aFailureBlock    失败block
 */
- (void)uploadFileWithFileModel:(nullable BDMUploadFileModel *)aUploadFileModel
               progressCallBack:(nullable void (^)(NSUInteger __unused bytesWritten,
                                                   long long totalBytesWritten,
                                                   long long totalBytesExpectedToWrite))progressBlock
                        success:(nullable void (^)(id _Nullable responseObject))aSuccessBlock
                        failure:(nullable void (^)(NSError * _Nullable error))aFailureBlock;
/**
 *  @brief  下载文件时调用方法
 *
 *  @param aDownloadModel 下载数据的model
 *  @param progressBlock  下载进度block
 *  @param aSuccessBlock  成功block
 *  @param aFailureBlock  失败block
 */
- (void)downloadFileWithFileModel:(nullable BDMDownloadFileModel *)aDownloadModel
                 progressCallBack:(nullable void (^)(NSUInteger bytesRead,
                                                     long long totalBytesRead,
                                                     long long totalBytesExpectedToRead))progressBlock
                          success:(nullable void (^)(id _Nullable responseObject))aSuccessBlock
                          failure:(nullable void (^)(NSError * _Nullable error))aFailureBlock;

- (void)cancelRequestForIdentifier:(nullable NSString *)requestID;
- (void)cancelRequestForIdentifierList:(nullable NSMutableArray *)requestIDList;
- (void)cancelAllRequest;

@end
